clear 
set more off 
set matsize 8000 
cap log close 

cd "D:\Data\workdata\707116\SIDS_RDD\"

use "SIDS_analysis_final_full.dta", clear

*log using "Revision1/log_files/04 Tables.log", replace



g dc_sids_oth = dc_sids + dc_all_other 

g 		mor1_exc_sids = mor1 - dc_sids_oth
replace mor1_exc_sids = 0 if mor1==0 

g 		mor5_exc_sids = mor5 - dc_sids_oth
replace mor1_exc_sids =0 if mor5==0 

g m_high_ed = m_short + m_mid + m_long
egen dc_other_non_sids = rowmax(dc_inf  dc_neo dc_nerv dc_resp)

g preterm = . 
replace preterm = 1 if fullterm37==0
replace preterm = 0 if fullterm37==1

g log_bw = ln(birthweight)




***Please check the labels and correct any)
label var mage "Mother age at birth" 
label var m_basic "Mother basic education" 
label var m_voc "Mother vocational education" 
label var m_high "Mother higher education" 
label var m_immigrant "Mother immigrant"  

label var female "Female" 
label var border "Birth order" 
label var preterm "Born preterm"
label var LBW "Low birthweight" 

label var dc_sids "SIDS mortality (over 10K)" 
label var dc_sids_oth "SIDS + all unclassified (over 10K)"
label var mor1 "Infant mortality" 
label var mor5 "Child mortality" 
label var mor1_exc_sids "Infant mortality except SIDS" 
label var mor5_exc_sids "Child mortality except SIDS" 


**TABLE 1 Summary Statistics**
**Make sure that these descriptive statistics loop over non-missing observations only 

tabstat female border birthweight LBW gage_wks preterm  ///
mage m_basic m_voc m_high m_couple m_immigrant ///
dc_sids dc_all_other mor1 mor5, ///
stat(mean sd n) format(%9.2f) long col(stat) 

fsum female border birthweight LBW gage_wks preterm  ///
mage m_basic m_voc m_high m_couple m_immigrant ///
dc_sids dc_all_other mor1 mor5, ///
stat(mean sd n) label 

fsum female border birthweight LBW gage_wks  preterm ///
mage m_basic m_voc m_high m_couple m_immigrant ///
dc_sids dc_all_other mor1 mor5, ///
stat(mean sd n) uselabel 

log close 